package com.ruoyi.common.translation.core.impl;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.service.TranslationService;
import com.ruoyi.common.translation.annotation.TranslationType;
import com.ruoyi.common.translation.constant.TransConstant;
import com.ruoyi.common.translation.core.TranslationInterface;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 字典翻译实现
 *
 * @author zhengyz
 */
@Service
@AllArgsConstructor
@TranslationType(type = TransConstant.DICT_TYPE_TO_LABEL)
public class DictTypeTranslationImpl implements TranslationInterface<String> {

    private final TranslationService dictService;

    /**
     *
     * @param key   字典的类型
     * @param other 具体的字典值
     * @return 字典中文描述
     */
    @Override
    public String translation(Object key, String other) {
        if (ObjectUtil.isNull(key)) {
            return null;
        }
        return dictService.dataTypeToLabel(other, key.toString());
    }
}
